import { ApiDoctorComment  } from "../../../api/index"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: {},
    list: [],
    loading: false,
    commentPermission: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      info: wx.getStorageSync("doctorPage")
    })
    
  },

  onShow() {
    this.getComment()
  },
  
  goMessageRoom() {
    const item = this.data.info
    const ops = {
      icon: item.icon,
      doctor_id: item.id,
      doctor_name: item.name,
      department_name: item?.department?.name ?? "",
      position: item.position,
    }
    wx.navigateTo({
      url: '/pages/visit/message/index?contact=' + JSON.stringify(ops),
    })
  },

  onClickComment() {
    wx.navigateTo({
      url: '/pages/visit/doctorRate/index?id='+this.data.info.id,
    })
  },

  goEvaluate() {
    wx.navigateTo({
      url: '/pages/visit/evaluate/index?id='+this.data.info.id,
    })
  },

  getComment() {
    this.setData({
      loading: true
    })
    ApiDoctorComment({page:1,size:10},this.data.info.id).then(res => {
      this.setData({
        list: res.data,
        commentPermission: res.commentPermission
      })
    }).finally(_=>{
      this.setData({
        loading: false
      })
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})